package at.codebase.core.search;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * 
 * @author Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
 *
 */
public class SortOption {
	
	private SortOptionType type;
	private SortOptionDetail detail;
	
	public SortOption(SortOptionType type, SortOptionDetail detail) {
		this.type = type;
		this.detail = detail;
	}

	public SortOptionType getType() {
		return type;
	}

	public SortOptionDetail getDetail() {
		return detail;
	}

	public static Map<String, SortOptionType> sortTypes = new HashMap<String, SortOption.SortOptionType>();
	public static Map<String, SortOptionDetail> sortDetails = new HashMap<String, SortOption.SortOptionDetail>();
	
	static{
		sortTypes.put("title", SortOptionType.TITLE);
		sortTypes.put("price", SortOptionType.PRICE);
		sortTypes.put("timeCreate", SortOptionType.TIME_CREATE);
		sortTypes.put("location", SortOptionType.LOCATION);
		sortTypes.put("description", SortOptionType.DESCRIPTION);
		
		sortDetails.put("asc", SortOptionDetail.ASCENDING);
		sortDetails.put("desc", SortOptionDetail.DESCENDING);
	}
	
	public enum SortOptionType {
		TITLE,
		PRICE,
		TIME_CREATE,
		LOCATION,
		DESCRIPTION
	}
	
	public enum SortOptionDetail {
		ASCENDING, DESCENDING
	}
	public static String getStringType(SortOptionType type){
		for (Entry<String, SortOption.SortOptionType> entry : sortTypes.entrySet()) {
	        if (type.equals(entry.getValue())) {
	            return entry.getKey();
	        }
	    }
	    return null;
	}
	
	public static String getStringDetail(SortOptionDetail detail){
		for (Entry<String, SortOption.SortOptionDetail> entry : sortDetails.entrySet()) {
	        if (detail.equals(entry.getValue())) {
	            return entry.getKey();
	        }
	    }
	    return null;
	}
	
}
